package simulation;


import java.util.List;

import util.Vector;


public class Viscosity extends Force{
	private double myCoefficient;
	private static final String DEFAULT_NAME = "Viscosity";
	private static final double DEFAULT_COEFFICIENT = 0.000000002;

	public Viscosity(){
		this(DEFAULT_COEFFICIENT);
	}
	public Viscosity(double viscosityConstant){
		super(DEFAULT_NAME);
		myCoefficient = viscosityConstant;
	}
	
	@Override
	public void apply(List<Mass> myMasses){
		if (!isOn()) 
			return;
		for(Mass m : myMasses){
			Vector force = calculateViscosityForce(m);
			m.applyForce(force);
		}
	}

	private Vector calculateViscosityForce(Mass m) {
		Vector currentVelocity = m.getVelocity();
		Vector force = currentVelocity;
		force.scale(myCoefficient);
		force.negate();
		return force;
	}
}
